package com.example.leetdemo.plan1;

public class Sword008 {

    public int minSubArrayLen(int target, int[] nums) {
        int[] res = new int[nums.length];
        int sum = 0, minLength = Integer.MAX_VALUE;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] >= target) {
                return 1;
            }
            sum += nums[i];
            res[i] = sum;
            if (sum > target) {
                for (int j = i - 1; j >= 0; j--) {
                    if (sum - res[j] >= target) {
                        minLength = Math.min(i - j, minLength);
                        break;
                    }
                }
            }
        }
        return minLength == Integer.MAX_VALUE ? 0 : minLength;
    }

    public static void main(String[] args) {
        Sword008 sword008 = new Sword008();
        System.err.println(sword008.minSubArrayLen(7, new int[]{2,3,1,2,4,3}));
    }
}
